home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / interp / perl-5.003.tar.gz / perl-5.003.tar / perl-5.003 / perly.fixer < prev    next >
Text File  |  1994-10-18  |  5KB  |  189 lines

  1. #!/bin/sh
  2.  
  3. # Fix up yacc output to allow dynamic allocation.  Since perly.c
  4. # is now provided with the perl source, this should not be necessary.
  5. #  
  6. # However, if the user wishes to use byacc, or wishes to try another 
  7. # compiler compiler (e.g. bison or yacc), this script will get run.
  8. #
  9. # Currently, only byacc version 1.8 is supported.
  10. #
  11. #  Hacks to make it work with Interactive's SysVr3 Version 2.2
  12. #   doughera@lafvax.lafayette.edu (Andy Dougherty)   3/23/91
  13. #
  14. # Additional information to make the BSD section work with SunOS 4.0.2
  15. #   tdinger@East.Sun.COM (Tom Dinger)    4/15/1991
  16.  
  17. input=$1
  18. output=$2
  19. tmp=/tmp/f$$
  20.  
  21. if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then
  22.     cp $input $output
  23.     if test -f perly.c.diff; then
  24.     patch -F3 $output <perly.c.diff
  25.     rm -rf $input
  26.     fi
  27.     exit
  28. elif grep 'yaccpar    1.9 (Berkeley)' $input >/dev/null 2>&1; then
  29.     if test -f perly.c.dif9; then
  30.     patch -F3 $output <perly.c.dif9
  31.     rm -rf $input
  32.     exit 0
  33.     else
  34.     echo "Diffs from byacc-1.9 are not available."
  35.     echo "If you wish to proceed anyway, do"
  36.     echo "cp $input $output"
  37.     echo "cp y.tab.h perly.h"
  38.     echo "and re-run make. Otherwise, I will use the old perly.c"
  39.     touch perly.c
  40.     # Exit with error status to stop make.
  41.     exit 1
  42.     fi
  43. fi
  44.  
  45. plan="unknown"
  46.  
  47. # Below, we check for various yaccpar outputs.
  48.  
  49. #  Test for BSD 4.3 version.
  50. #  Also tests for the SunOS 4.0.2 version
  51. egrep 'YYSTYPE[     ]*yyv\[ *YYMAXDEPTH *\];
  52. short[  ]*yys\[ *YYMAXDEPTH *\] *;
  53. yyps *= *&yys\[ *-1 *\];
  54. yypv *= *&yyv\[ *-1 *\];
  55. if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
  56.  
  57. set `wc -l $tmp`
  58. if test "$1" = "5"; then
  59.       plan="bsd43"
  60. fi
  61.  
  62. if test "$plan" = "unknown"; then
  63.     #   Test for ISC 2.2 version (probably generic SysVr3).
  64. egrep 'YYSTYPE[     ]*yyv\[ *YYMAXDEPTH *\];
  65. int[    ]*yys\[ *YYMAXDEPTH *\] *;
  66. yyps *= *&yys\[ *-1 *\];
  67. yypv *= *&yyv\[ *-1 *\];
  68. if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
  69.  
  70.     set `wc -l $tmp`
  71.     if test "$1" = "5"; then
  72.     plan="isc"
  73.     fi
  74. fi
  75.  
  76. case "$plan" in
  77.     ##################################################################
  78.     # The SunOS 4.0.2 version has the comparison fixed already.
  79.     # Also added are out of memory checks (makes porting the generated
  80.     # code easier) For most systems, it can't hurt. -- TD
  81.     "bsd43")
  82.     echo "Patching perly.c to allow dynamic yacc stack allocation"
  83.     echo "Assuming bsd4.3 yaccpar"
  84.     cat >$tmp <<'END'
  85. /YYSTYPE[     ]*yyv\[ *YYMAXDEPTH *\];/c\
  86. int yymaxdepth = YYMAXDEPTH;\
  87. YYSTYPE *yyv; /* where the values are stored */\
  88. short *yys;\
  89. short *maxyyps;
  90.  
  91. /short[     ]*yys\[ *YYMAXDEPTH *\] *;/d
  92.  
  93. /yyps *= *&yys\[ *-1 *\];/d
  94.  
  95. /yypv *= *&yyv\[ *-1 *\];/c\
  96. \    if (!yyv) {\
  97. \        yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\
  98. \        yys = (short*) safemalloc(yymaxdepth * sizeof(short));\
  99. \        if ( !yyv || !yys ) {\
  100. \        yyerror( "out of memory" );\
  101. \        return(1);\
  102. \        }\
  103. \        maxyyps = &yys[yymaxdepth];\
  104. \    }\
  105. \    yyps = &yys[-1];\
  106. \    yypv = &yyv[-1];
  107.  
  108.  
  109. /if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\
  110. \        if( ++yyps >= maxyyps ) {\
  111. \            int tv = yypv - yyv;\
  112. \            int ts = yyps - yys;\
  113. \
  114. \            yymaxdepth *= 2;\
  115. \            yyv = (YYSTYPE*)realloc((char*)yyv,\
  116. \              yymaxdepth*sizeof(YYSTYPE));\
  117. \            yys = (short*)realloc((char*)yys,\
  118. \              yymaxdepth*sizeof(short));\
  119. \            if ( !yyv || !yys ) {\
  120. \            yyerror( "yacc stack overflow" );\
  121. \            return(1);\
  122. \            }\
  123. \            yyps = yys + ts;\
  124. \            yypv = yyv + tv;\
  125. \            maxyyps = &yys[yymaxdepth];\
  126. \        }
  127.  
  128. /yacc stack overflow.*}/d
  129. /yacc stack overflow/,/}/d
  130. END
  131.     sed -f $tmp <$input >$output ;;
  132.  
  133.     #######################################################
  134.     "isc") # Interactive Systems 2.2  version
  135.     echo "Patching perly.c to allow dynamic yacc stack allocation"
  136.     echo "Assuming Interactive SysVr3 2.2 yaccpar"
  137.     # Easier to simply put whole script here than to modify the
  138.     # bsd script with sed.
  139.     # Main changes:  yaccpar sometimes uses yy_ps and yy_pv
  140.     # which are local register variables.
  141.     #  if(++yyps > YYMAXDEPTH) had opening brace on next line.
  142.     # I've kept that brace in along with a call to yyerror if
  143.     # realloc fails. (Actually, I just don't know how to do
  144.     # multi-line matches in sed.)
  145.     cat > $tmp << 'END'
  146. /YYSTYPE[     ]*yyv\[ *YYMAXDEPTH *\];/c\
  147. int yymaxdepth = YYMAXDEPTH;\
  148. YYSTYPE *yyv; /* where the values are stored */\
  149. int *yys;\
  150. int *maxyyps;
  151.  
  152. /int[     ]*yys\[ *YYMAXDEPTH *\] *;/d
  153.  
  154. /yyps *= *&yys\[ *-1 *\];/d
  155.  
  156. /yypv *= *&yyv\[ *-1 *\];/c\
  157. \    if (!yyv) {\
  158. \        yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\
  159. \        yys = (int*) safemalloc(yymaxdepth * sizeof(int));\
  160. \        maxyyps = &yys[yymaxdepth];\
  161. \    }\
  162. \    yyps = &yys[-1];\
  163. \    yypv = &yyv[-1];
  164.  
  165. /if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\
  166. \        if( ++yy_ps >= maxyyps ) {\
  167. \            int tv = yy_pv - yyv;\
  168. \            int ts = yy_ps - yys;\
  169. \
  170. \            yymaxdepth *= 2;\
  171. \            yyv = (YYSTYPE*)realloc((char*)yyv,\
  172. \              yymaxdepth*sizeof(YYSTYPE));\
  173. \            yys = (int*)realloc((char*)yys,\
  174. \              yymaxdepth*sizeof(int));\
  175. \            yy_ps = yyps = yys + ts;\
  176. \            yy_pv = yypv = yyv + tv;\
  177. \            maxyyps = &yys[yymaxdepth];\
  178. \        }\
  179. \        if (yyv == NULL || yys == NULL)
  180. END
  181.     sed -f $tmp < $input > $output ;;
  182.  
  183.     ######################################################
  184.     # Plan still unknown
  185.     *) sed -e 's/Received token/ *** Received token/' $input >$output;
  186. esac
  187.  
  188. rm -rf $tmp $input
  189.